angular.module("seatMapApp", ['ui.bootstrap', 'httpService2']).controller("seatMapCtrl", ['$scope', '$http', '$uibModal', '$timeout', 'mapService',
function($scope, $http, $uibModal, $timeout, mapService) {

    var map = new BMap.Map("allmap");
    // 创建Map实例
    map.centerAndZoom(new BMap.Point(105.004872, 29.912039), 9);
    // 初始化地图,设置中心点坐标和地图级别
    map.setCurrentCity("乐山");
    // 设置地图显示的城市 此项是必须设置的
    map.enableScrollWheelZoom(true);
    //开启鼠标滚轮缩放

    $scope.getLocation = function() {
        var geolocation = new BMap.Geolocation();
        geolocation.getCurrentPosition(function(r) {
            if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                var mk = new BMap.Marker(r.point);
                map.addOverlay(mk);
                map.panTo(r.point);
      //          alert('您的位置：' + r.point.lng + ',' + r.point.lat);
            } else {
                alert('failed' + this.getStatus());
            }
        }, {
            enableHighAccuracy : true
        });
    };
 //   $scope.getLocation();
    $scope.showData = function() {
        mapService.getSeatMapData().then(function(response) {
            angular.forEach(response, function(data) {
                var point = new BMap.Point(data.longtitude, data.latitude);
                var marker = new BMap.Marker(point);
                var content = '<div style="margin:0;line-height:20px;padding:2px;">' + data.detail + '</div>';
                var searchInfoWindow = new BMapLib.SearchInfoWindow(map, content, {
                    title : data.name, //标题
                    width : 240, //宽度
                    height : 105, //高度
                    panel : "panel", //检索结果面板
                    enableSendToPhone: false, 
                    enableAutoPan : true, //自动平移
                    searchTypes : [
                    BMAPLIB_TAB_SEARCH, //周边检索
                    BMAPLIB_TAB_TO_HERE, //到这里去
                    BMAPLIB_TAB_FROM_HERE //从这里出发
                    ]
                });
                marker.addEventListener("click", function(e) {
                    searchInfoWindow.open(marker);
                });
                map.addOverlay(marker);
            });

        });
    };
    $scope.showData();

}]);
